#ifndef __CONSOLE_H__
#define __CONSOLE_H__

//#include "stdafx.h"

class Console
{
public:
	Console(HANDLE h);
	~Console();

	enum E_CONSOLE
	{
		CONSOLE_INPUT	= STD_INPUT_HANDLE,
		CONSOLE_OUTPUT	= STD_OUTPUT_HANDLE,
		CONSOLE_ERROR	= STD_ERROR_HANDLE,
	};
	Console(E_CONSOLE eConsole);

	HANDLE	get_handle();

	LPCTSTR	get_title();
	bool	set_title(const std::tstring& val);

protected:	// Helper functions.
	void init(HANDLE h);
	void clear();

private:
	HANDLE	hConsole;

	static const int MAX_TITLE = 32;
	TCHAR Title[MAX_TITLE];
};

///////////////////////////////////////////////////////////////////////////////

class InputConsole :
	public Console
{
public:
	InputConsole() :
	  Console(CONSOLE_INPUT)
	{}

	void	peek_input();
	void	read();
	void	read_input();
	void	read_output();
	void	read_output_char();

	bool	flush();

};

///////////////////////////////////////////////////////////////////////////////

class OutputConsole :
	public Console
{
public:
	OutputConsole() :
	  Console(CONSOLE_OUTPUT)
	{}

	void	scroll_screen();

	// returns NumberOfCharsWritten
	DWORD	fill(TCHAR cCharacter, DWORD nLength, COORD dwWriteCoord);
	DWORD	fill(TCHAR cCharacter, DWORD nLength, SHORT X, SHORT Y);

	// Write at current cursor position,
	// returns number of bytes written.
	DWORD	write(const void* Buffer, DWORD nLength);
	void	write_input();
	void	write_output();
	void	write_output_char();
};

#endif


